#!usr/bin/node

const http = require('http'),
      html = `
      <!DOCTYPE html>
      <html>
        <header>
          <title>index</title>
        </header>
        <body>
          hello world
        </body>
      </html>`;
      

http.createServer((req,res) => {
  console.log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  console.log(req.headers);

  if(req.url === '/') {
    res.writeHead(200,{'Content-Type':'text/html','Content-Length':Buffer.byteLength(html)});
    res.end(html); 
  }else {
   res.statusCode = 404;
   res.end('Resource not found');
  }
}).listen(8080);
